package info.yaohua.servlet;

import info.yaohua.dao.Ac02Dao;
import info.yaohua.dto.Ac01Dto;
import info.yaohua.dto.Ac02Dto;
import info.yaohua.util.SessionNull;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class PostQueryServlet
 */
@WebServlet("/PostQueryServlet")
public class PostQueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PostQueryServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		if (session == null || session.getAttribute("ac01")==null) {
			SessionNull.forwordTo(request, response);
		} else {
			Ac02Dao ac02Dao = new Ac02Dao();
			Ac02Dto ac02Dto = new Ac02Dto();
			Ac01Dto ac01Dto = (Ac01Dto) session.getAttribute("ac01");
			ac02Dto.setAac001(ac01Dto.getAac001());
			try {
				ArrayList<Ac02Dto> list_ac02 = ac02Dao.findAc02ByAac001(ac02Dto);
				int count = list_ac02.size();
				request.setAttribute("list_ac02", list_ac02);
				request.setAttribute("count", count);
				RequestDispatcher view1 = request.getRequestDispatcher("/archives.jsp");
				view1.forward(request, response);
			} catch (NamingException | SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
